FROM ubuntu:24.04

ARG DEBIAN_FRONTEND=noninteractive
ARG DOWNLOAD_URL

RUN apt-get update \
    && apt-get install --yes --no-install-recommends \
        ca-certificates \
        wget \
        tar \
        bash \
        net-tools \
        openjdk-21-jre-headless \
        python3.12 \
        python3.12-venv \
        fontconfig \
        locales \
        tzdata \
        procps \
        htop \
        curl \
    && ln -fs /usr/bin/python3.12 /usr/bin/python3 \
    && ln -fs /usr/share/zoneinfo/UTC /etc/localtime \
    && echo "UTC" > /etc/timezone \
    && locale-gen en_US.UTF-8 \
    && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ENV TZ=UTC \
    LANG=en_US.UTF-8 \
    LC_ALL=en_US.UTF-8 

RUN groupadd -r tdengine --gid=101 \
    && useradd -r -g tdengine --uid=101 --home-dir=/home/tdengine --shell=/bin/bash tdengine

RUN wget --progress=bar:force:noscroll "${DOWNLOAD_URL}" -O /tmp/tdengine-idmp-enterprise-linux.tar.gz \
    && tar -xzf /tmp/tdengine-idmp-enterprise-linux.tar.gz -C /tmp \
    && rm -f /tmp/tdengine-idmp-enterprise-linux.tar.gz \
    && cd /tmp/tdengine-idmp-enterprise-* \
    && ./install.sh -s -n \
    && rm -rf /tmp/* \
    && chown -R tdengine:tdengine /usr/local/taos/idmp \
    && chown -R tdengine:tdengine /var/log/taos \
    && chown -R tdengine:tdengine /var/lib/taos

RUN mkdir -p /opt/arthas \
    && curl -L -o /opt/arthas/arthas-boot.jar https://arthas.aliyun.com/arthas-boot.jar \
    && echo '#!/bin/sh\njava -jar /opt/arthas/arthas-boot.jar "$@"' > /usr/local/bin/arthas \
    && chmod +x /usr/local/bin/arthas

COPY entrypoint.sh /entrypoint.sh

RUN chmod +x /entrypoint.sh

EXPOSE 6042

USER tdengine

WORKDIR /home/tdengine

ENTRYPOINT ["/entrypoint.sh"]
